package cn.open.feishu.alert.common.utils;

import cn.open.feishu.alert.config.ButtonProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;

import java.util.Date;

/**
 * @Description 获取告警文本按钮链接信息工具类(可供参考)
 * @Author fandy.lin
 * @Date 2021/11/11 4:20 下午
 **/
@Slf4j
public class LinkUtil {

    public static String getLogUrl(Environment env, ButtonProperties properties, Date from, Date to) {
        StringBuilder urlBuilder = new StringBuilder();
        urlBuilder.append(properties.getLogUrl())
                .append("?_g=(refreshInterval:(pause:!t,value:0),")
                .append("time:(from:'").append(TimeUtil.dateFormatUtc(from)).append("',to:'").append(TimeUtil.dateFormatUtc(to)).append("'))")
                .append("&_a=(columns:!(message,request),filters:!(),interval:auto,query:(language:lucene,query:error)")
                .append(",senv:").append(env.getProperty("env"))
                .append(",sname:").append(env.getProperty("app.id"))
                .append(",sort:!(),stype:").append(properties.getLogStype()).append(")");
        return urlBuilder.toString();
    }

    public static String getMonitorUrl(Environment env, ButtonProperties properties) {
        StringBuilder urlBuilder = new StringBuilder();
        urlBuilder.append(properties.getMonitorUrl())
                .append("?appid=").append(env.getProperty("app.id"))
                .append("&env=").append(env.getProperty("env"));
        return urlBuilder.toString();
    }
}
